﻿<?php
	// session_start();
	
	if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: ad-dangnhap.php");
	}
	
	include "connect.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Trang Chủ</title>
<style type="text/css">
<!--
image{border:none;}
a	{
		color: #006600;
		text-decoration: none;
	}

a:hover { COLOR: #CC0000}

.thongbao{font-size:18px; font-weight:bold; color:#FF0000;}
.mau{background:#FFCC99;}

.style6 {
	color: #FFFFFF;
	font-weight: bold;
	font-size: 30px;
}
.style7 {
	font-size: 18px;
	font-weight: bold;
	color: #FFFFFF;
  
}
.style8 {
	font-size: 16px;
	color: #FFFFFF;
  
}
.style9 {color: #006600; font-weight: bold; font-size: 18px; }
.style10 {color:#990033; font-size: 18px; }

-->
</style>
</head>
<body>

<table width="700" align="center">
	<tr > 
	   <td height="40" align="right"><a href="ad-trangchu.php?nav=themsv" class="style9"><img src="image/them.png" />&nbsp; Thêm mới Sinh Viên</a></td>
	</tr>

	<tr>
		<td>
		<!--chứa bảng tìm kiếm sinh viên -->
			<table width="700" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0">
						
					  <tr> 
							<td height="25" colspan="3" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
								<span class="style7">Tìm Sinh Viên Cập nhật</span></td>
					  </tr>
						
						<tr bordercolor="#FFFFFF"> 
						  <td colspan="3" height="50" align="center" style="font-size:18px">
						  
								  <form name="f" method="post">
										  
											Mã Số Sinh Viên :    &nbsp;&nbsp;			
											<input type="text" name="mssv" /> &nbsp;&nbsp;
											  
										   <input name="tk" type="submit"  id="tk" value="   Tìm Kiếm  " />
								  </form>
						 </td>
					  </tr>
					  <tr bordercolor="#FFFFFF">
						  <td colspan="3" align="center" class="style10">( Xin vui lòng nhập vào chính xác Mã Số Sinh Viên cần cập nhật )</td>
					  </tr>
					
			</table>
		</td>
	</tr>
</table>

<table>
     <tr>
	     <td height="30"></td>
	 </tr>
</table>

<?php
if (isset($_POST["mssv"]))
{
     $mssv = $_POST["mssv"];
	 if ($mssv != "")
	 {
			 $sql_query=mysql_query("select * from `sinh vien` where ma_sv = '$mssv' ");
			 if(mysql_num_rows($sql_query)==0)
				{
				 echo "<div align='center' class='thongbao'>Không có Sinh Viên nào!</div>";
				}
			 else
				{
				    $r=mysql_fetch_row($sql_query);
					$tensv=$r[1];
					$email_sv=$r[2];
					$namsinh_sv=$r[3];
					$gioitinh_sv=$r[4];
					$malop=$r[6];

?>
									 <form name="f" method="post" action="" onsubmit="">
							  <table width="500" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0">
									
								  <tr> 
										<td height="30" colspan="2" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
											<span style="font-size:24px; color:#FFFFFF; font-weight:bold;">Thông tin Sinh Viên</span></td>
								  </tr>
									
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Mã Số Sinh Viên:</td>
									 <td align="left"><input type="text" name="ms" value="<?php echo $mssv; ?>"  class="mau" readonly=""/></td>
								  </tr>
								  
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Họ Tên Sinh Viên:</td>
									 <td align="left"><input type="text" name="tensv" value="<?php echo $tensv; ?>"  /></td>
								  </tr>
								  
								 <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Giới Tính Sinh Viên:</td>
									 <td align="left">
									 <?php 
									 if($gioitinh_sv==1) echo "
									      <input type='radio' name='gtsv' value='1' checked='checked' /> Nam &nbsp;&nbsp;<input type='radio' name='gtsv' value='0' /> Nữ";
					
									 else  echo"
									     <input type='radio' name='gtsv' value='1' /> Nam &nbsp;&nbsp;<input type='radio' name='gtsv' value='0' checked='checked'  /> Nữ "  ;?>
								     </td>
								  </tr> 
								  
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Năm Sinh Sinh Viên:</td>
									 <td align="left"><input type="text" name="nssv" size="4" value="<?php echo $namsinh_sv; ?>" /></td>
								  </tr>
								  
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Email Sinh Viên:</td>
									 <td align="left"><input type="text" name="emsv" value="<?php echo $email_sv; ?>" /></td>
								  </tr>
								  
								   <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Mã Lớp Sinh Viên:</td>
									
									<td align="left">
										<select name="cboMaLop">
											<?php
												$query = "select * from `lop sinh vien`";
												$result = mysql_query($query, $db) or die(mysql_error());
												while ($row = mysql_fetch_array($result))
												{
													echo '<option value="'.$row["ma_lop"].'"';
													
													if ($row["ma_lop"] == $malop)
														echo " selected";
													
													echo '>'.$row["ma_lop"].' - '.$row["ten_lop"].'</option>';
												}
											?>
										</select>
									</td>
								  </tr>
								  
								  <tr bordercolor="#FFFFFF">
									  <td  align="right" height="30"><input type="submit" value="Cập nhật" name="cn" /></td>
									  <td align="center"><input type="reset" value="Làm Lại" name="huy" /></td>
								 </tr>
								
						</table>
				  </form>	
				  
				<?php 
				}
			}
}
				?>  
				
<table>
     <tr>
	     <td height="30"></td>
	 </tr>
</table>	
<?php 
                if(isset($_POST["cn"]))
				{
				          $ms=$_POST["ms"];
				          $ht=$_POST["tensv"];
						  $gt=$_POST["gtsv"];
						  $ns=$_POST["nssv"];
						  $em=$_POST["emsv"];
						  $ml=$_POST["malopsv"];
						 // $kq=mysql_query(" update `sinh vien` set ten_sv='$ht',email_sv='$em',namsinh_sv='$ns',gioitinh_sv='$gt',malop_sv='$ml' where ma_sv='$ms' ");
						 $kq=mysql_query(" update `sinh vien` set ten_sv='$ht',email_sv='$em', namsinh_sv='$ns',gioitinh_sv='$gt',ma_lop='$ml' where ma_sv='$ms' ");
						  echo"<script type='text/javascript'>alert('Cap Nhat Thanh Cong')</script>";
		                  echo'<meta http-equiv="refresh" content="0;URL=ad-trangchu.php?nav=cnsv">';
						  
				}
?>
</body>
</html>
